//
//  PTRecorderView.m
//  PocketTutor
//
//  Created by yate1996 on 15/6/9.
//  Copyright (c) 2015年 yate1996. All rights reserved.
//

#import "PTRecorderView.h"
#import "PTRecorderFrame.h"
#import "PTRecorder.h"
#import "PTRecorderCell.h"
@interface PTRecorderView ()


@end

@implementation PTRecorderView


-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if(self) {
        
        UILabel *teacherNameLabel = [[UILabel alloc]init];
        teacherNameLabel.font = PTHelveticaNeueLight14;
        [self addSubview:teacherNameLabel];
        self.teacherNameLabel = teacherNameLabel;
        
        UIButton *lessonTitleButton = [[UIButton alloc]init];
        lessonTitleButton.titleLabel.font = PTHelveticaNeue14;
        lessonTitleButton.tag = PTRecorderButtonTypelessonTitle;
        [self addSubview:lessonTitleButton];
        self.lessonTitleButton = lessonTitleButton;
        
        UIButton *actionOrCancelButton = [[UIButton alloc]init];
        actionOrCancelButton.titleLabel.font = PTHelveticaNeueLight12;
        actionOrCancelButton.tag = PTRecorderButtonTypeactionOrCancel;
        [self addSubview:actionOrCancelButton];
//        [actionOrCancelButton setUserInteractionEnabled:NO];
        self.actionOrCancelButton = actionOrCancelButton;
        
        UIImageView *teacherIconView = [[UIImageView alloc]init];
        [self addSubview:teacherIconView];
        self.teacherIconView = teacherIconView;
        
        UILabel *countDownLabel = [[UILabel alloc]init];
        countDownLabel.font = PTHelveticaNeueLight12;
        [self addSubview:countDownLabel];
        self.countDownLabel = countDownLabel;
        
        
        
    }
    return self;
}

-(void)setRecorderFrame:(PTRecorderFrame *)recorderFrame
{
    
    _recorderFrame = recorderFrame;
    self.frame = recorderFrame.frame;
    
    PTRecorder *recorder = recorderFrame.recorder;
    
    self.teacherNameLabel.text = recorder.teacherName;
    self.teacherNameLabel.frame = recorderFrame.teacherNameFrame;
    self.teacherNameLabel.textColor = PTColor(103 , 103, 110, 1.0);
    
    
    [self.lessonTitleButton setTitle:recorder.lessonTitle forState:UIControlStateNormal];
    [self.lessonTitleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.lessonTitleButton.frame = recorderFrame.lessonTitleFrame;
    self.teacherNameLabel.textColor = PTColor(103 , 103, 110, 1.0);

    
    [self.actionOrCancelButton setTitle:recorder.actionOrCancel forState:UIControlStateNormal];
    self.actionOrCancelButton.frame = recorderFrame.actionOrCancelFrame;
    [self.actionOrCancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.actionOrCancelButton setUserInteractionEnabled:YES];
    if([self.actionOrCancelButton.titleLabel.text isEqualToString:@"Study Now"]||[self.actionOrCancelButton.titleLabel.text isEqualToString:@"Cancel"])
    {
        self.actionOrCancelButton.titleEdgeInsets = UIEdgeInsetsZero;
        [self.actionOrCancelButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [self.actionOrCancelButton setBackgroundImage:[UIImage imageNamed:@"recordsUnselectButton"] forState:UIControlStateNormal];
        [self.actionOrCancelButton setBackgroundImage:[UIImage imageNamed:@"recordsButton"] forState:UIControlStateHighlighted];
        [self.actionOrCancelButton setImage:nil forState:UIControlStateNormal];
        [self.actionOrCancelButton.titleLabel setTextAlignment:NSTextAlignmentCenter];

        
    } else {
        self.actionOrCancelButton.titleLabel.numberOfLines = 0;
        [self.actionOrCancelButton setBackgroundImage:nil forState:UIControlStateNormal];
        [self.actionOrCancelButton setBackgroundImage:nil forState:UIControlStateHighlighted];
        [self.actionOrCancelButton setImage:[UIImage imageNamed:@"arrow_right"] forState:UIControlStateNormal];
        self.actionOrCancelButton.titleEdgeInsets = UIEdgeInsetsMake(0, -25, 0, 0);
        self.actionOrCancelButton.imageEdgeInsets = UIEdgeInsetsMake(0, 68, 0, 0);
        [self.actionOrCancelButton.titleLabel setTextAlignment:NSTextAlignmentRight];
    }
    
    
    self.teacherIconView.image = [UIImage imageNamed:recorder.lessonIcon];
    self.teacherIconView.frame = recorderFrame.lessonIconFrame;
    
    
    self.countDownLabel.text = recorder.countDown;
    self.countDownLabel.frame = recorderFrame.countDownFrame;
    self.countDownLabel.textColor = PTColor(103 , 103, 110, 1.0);

//        [self.countDownButton setBackgroundImage:[UIImage resizedImage:@"Buttonbackground"] forState:UIControlStateNormal];

    
    
    
}

@end
